//
//  YmSidVPickColorView.swiftebFYXR
//  QRScan
//
//  Created by Qiang on 2018/3/27.
//  Copyright © 2018年 Qiang. All rights reserved.
//

import UIKit

class YmSidVPickColorView: UIView {
    typealias block = (_ index:NSInteger)->Void
    var buttonClick:block!
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
     func setupSubView(){
        
        let imgV = UIImageView(frame: CGRect(x: 40, y: self.frame.height-9, width: 14, height: 8))
        imgV.image = UIImage(named: "downArraw")
        self.addSubview(imgV)
        
        let v = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height-8))
        v.backgroundColor = UIColor.black.withAlphaComponent(0.8)
        v.layer.cornerRadius = 10
        v.clipsToBounds = true
        self.addSubview(v)
        
        for i in 0..<18 {
            let button = UIButton(type: .custom)

            button.frame = CGRect(x: i%6 * (30 + 120/7)+120/7, y: 14+(14+30) * (i/6), width: 30, height: 30)
            button.backgroundColor = [UIColor.lightGray,UIColor.gray,UIColor.darkGray,colorWithRGB(245, g: 166, b: 189, a: 1),colorWithRGB(152, g: 184, b: 185, a: 1),colorWithRGB(100, g: 148, b: 181, a: 1),colorWithRGB(58, g: 181, b: 175, a: 1),UIColor.red,colorWithRGB(59, g: 181, b: 84, a: 1),colorWithRGB(211, g: 210, b: 135, a: 1),UIColor.purple,colorWithRGB(246, g: 159, b: 46, a: 1),colorWithRGB(220, g: 98, b: 79, a: 1),UIColor.brown,colorWithRGB(40, g: 176, b: 255, a: 1),colorWithRGB(255, g: 161, b: 46, a: 1),colorWithRGB(211, g: 178, b: 255, a: 1),UIColor.blue][i]
            button.layer.cornerRadius = 15
            button.tag = 1+i
            button.addTarget(self, action: #selector(buttonClick(button:)), for: .touchUpInside)
            self.addSubview(button)
        }
        
        
        
    }
    @objc private func buttonClick(button:UIButton){
        if self.buttonClick != nil {
            self.buttonClick(button.tag)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
